{include file="public/header"}
<body>
<style>
    .el-tag + .el-tag {
        margin-left: 10px;
    }
    .button-new-tag {
        margin-left: 10px;
        height: 32px;
        line-height: 30px;
        padding-top: 0;
        padding-bottom: 0;
    }
    .input-new-tag {
        width: 90px;
        margin-left: 10px;
        vertical-align: bottom;
    }
</style>
<div id="app" v-cloak>
    <div class="ht-main">
        <div class="ht-search">
            <el-form :inline="true" size="small">
                <el-form-item label="商品">
                    <el-select v-model="searchKey.goods_id" filterable clearable>
                        <el-option :value="item.id" :label="item.title"
                                   v-for="item in goodsList" :key="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" icon="el-icon-search" @click="search">搜索</el-button>
                    <el-button type="" icon="el-icon-refresh" @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="ht-tool">
            <div class="ht-tool-left">
<!--                <el-button type="success" size="mini" icon="el-icon-plus" @click="doAdd">添加</el-button>-->
<!--                <el-button type="primary" :disabled="tableSelect.length !== 1" size="mini" icon="el-icon-edit"-->
<!--                           @click="edit(tableSelect[0])">编辑-->
<!--                </el-button>-->
                <el-button type="danger" :disabled="!tableSelect.length" size="mini" icon="el-icon-delete"
                           @click="batchDel('/admin/comment/del')">删除
                </el-button>
            </div>
            <div class="ht-tool-right">
            </div>
        </div>
        <div class="ht-main-body">
            <el-table :data="tableData" border header-row-class-name="ht-table-header"
                      ref="dataTable" @selection-change="handleSelectChange"
                      row-key="title"
                      :tree-props="{children:'children'}"
            >
                <el-table-column
                        align="center"
                        type="selection"
                        width="39">
                </el-table-column>
                <el-table-column align="center" width="180px"
                                 prop="goods.title"
                                 label="商品">
                </el-table-column>
                <el-table-column
                        align="center" width="100px"
                        prop="user.nick"
                        label="用户">
                </el-table-column>
                <el-table-column
                        prop="content"
                        label="内容">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="create_time"
                        width="180px"
                        label="添加时间">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="操作"
                        width="140">
                    <template slot-scope="scope">
<!--                        <el-button @click="edit(scope.row)" size="mini" type="primary" icon="el-icon-edit"></el-button>-->
                        <el-button @click="del(scope.row)" size="mini" type="danger" icon="el-icon-delete"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="ht-main-page">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page"
                        :page-sizes="[1,10, 200, 300, 400]"
                        :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <el-drawer
                    :visible.sync="is_edit"
                    size="100%"
                    :with-header="false"
                    custom-class="ht-drawer-bg"
            >
                <div class="ht-drawer-main">
                    <el-page-header @back="goBack" title="Esc返回" :content="content"></el-page-header>
                    <div class="ht-form">
                        <el-form :model="editData" label-width="120px" size="small">
                            <el-form-item label="分类名称">
                                <el-input type="text" placeholder="分类名称" v-model="editData.title"></el-input>
                            </el-form-item>
                            <el-form-item label="上级分类">
                                <el-select v-model="editData.pid" filterable clearable>
                                    <el-option :value="0" label="无上级"></el-option>
                                    <el-option :value="item.id" :label="item.title"
                                               v-for="item in categoryList" :key="item.id"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="分类排序">
                                <el-input type="text" placeholder="分类排序" v-model="editData.sort"></el-input>
                            </el-form-item>
                            <el-form-item label="分类图片">
                                <el-input type="text" placeholder="商品图片" v-model="editData.image" style="width: 70%"></el-input>
                                <el-button type="primary" @click="imageOpen()">选择图片</el-button>
                            </el-form-item>
                            <el-form-item v-if="editData.image">
                                <el-image style="max-width: 100px;max-height: 100px;cursor: pointer" :src="editData.image"
                                          @click="showImg(editData.image)"></el-image>
                            </el-form-item>
                            <el-form-item>
                                <el-button @click="goBack">取消</el-button>
                                <el-button type="primary" @click="onSubmit">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </el-drawer>
        </div>

    </div>
</div>
{include file="public/common"}
<script>
    let vs ;
    let del_url = "{:url('Comment/del')}";
    let add_url = "{:url('Comment/add')}";
    let index_url = "{:url('Comment/index')}";
    var vm = new Vue({
        el: "#app",
        data: function () {
            return {
                inputValue: '',
                inputVisible: false,
                showDialog: false,
                activeTab: 'first',
                tableData: [],
                goodsList:[],
                is_edit: false,
                editData: {},
                editDataTemp: {},
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                fileManage:false,
                options:[],
                contacts:[{name:'',tel:''}]
            }
        },
        created: function () {
            vs = this;
            vs.getGoods();
            vs.getData()
        },
        methods: {
            handleClose(tag) {
                vs.editData.flag.splice(vs.editData.flag.indexOf(tag), 1);
                console.log(vs.editData.flag)
                vs.is_edit = false
                vs.is_edit = true
            },

            showInput() {
                this.inputVisible = true;
                this.$nextTick(_ => {
                    this.$refs.saveTagInput.$refs.input.focus();
                });
            },

            handleInputConfirm() {
                let inputValue = this.inputValue;
                if (inputValue) {
                    if (!vs.editData.flag) {
                        vs.editData.flag = []
                    }
                    vs.editData.flag.push(inputValue);
                }
                this.inputVisible = false;
                this.inputValue = '';
            },
            delContact(index) {
                vs.contacts.splice(index,1)
            },
            addContact() {
                vs.contacts.push({name:'',tel:''})
            },
            getArea() {
                $.post("{:url('Area/getAreaList')}",function (res) {
                    if (res.code == 1) {
                        vs.options = res.data
                    }
                })
            },
            getShop() {
                $.post("{:url('shop/all')}",function (res) {
                    if (res.code == 1) {
                        vs.shopList = res.data
                    }
                })
            },
            getAdmin() {
                $.post("{:url('admin/all')}",function (res) {
                    if (res.code == 1) {
                        vs.adminList = res.data
                    }
                })
            },
            getGoods() {
                $.post("{:url('Goods/all')}",function (res) {
                    if (res.code == 1) {
                        vs.goodsList = res.data
                    }
                })
            },
            upSuccess(list) {
                console.log(list)
            },
            imageManageClose(path) {
                this.showDialog = false;
            },
            imageSubmit(path) {
                console.log("path", path)
                this.editDataTemp.image = path[0]
                this.editData.image = path[0]
                this.showDialog = false;
            },
            imageManage() {
                this.showDialog = true;
            },
            uploadSuccess(litpic, value) {
                this.editDataTemp.litpic = litpic
                this.editData.litpic = litpic
            },

            changeStatus: function (e, id) {
                axios.post("{:url('Archives/ArchivesStatus')}", {id: id}).then((res) => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            changeMenuStatus: function (e, id) {
                axios.post("{:url('Auth/menuStatus')}", {id: id}).then((res) => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            onSubmit() {
                var that = this
                vs.editData.contacts = vs.contacts;
                $.post(add_url, that.editData, function (res) {
                    if (res.code == 1) {
                        that.showSuccessMsgCall(function () {
                            that.is_edit = false;
                            that.editData = {};
                            that.getData()
                        })
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },

            getData: function () {
                var that = this
                that.searchType = {
                    title: 'like',
                    flag: 'like'
                };
                $.post(index_url, {
                    limit: that.limit,
                    page: that.page,
                    search_key: that.searchKey,
                    search_type: that.searchType
                }, function (res) {
                    if (res.code == 1) {
                        that.tableData = res.data.data
                        that.total = res.data.total
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },
            doAdd: function () {
                this.is_edit = true
                this.content = '添加'
                this.editData = {
                    pid:0
                }
                vs.contacts = []
            },
            edit: function (data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = data
                vs.contacts = data.contacts
                if (!vs.contacts) {
                    vs.contacts = [{}]
                }
                console.log(data)
            },
            goBack: function () {
                this.is_edit = false
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    $.post(del_url, {id: data.id}, function (res) {
                        if (res.code == 1) {
                            that.showSuccessMsgCall(function () {
                                that.getData()
                            })
                        } else {
                            that.showErrorMsg(res.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {
            page(v) {
                this.getData()
            },
            limit() {
                this.getData()
            }
        }
    })
</script>
</body>
</html>
